package com.cnt.controller;

import com.cnt.service.DonationRecordsService;
import com.cnt.service.DonationsInfoService;
import com.cnt.service.DonationsService;
import com.cnt.vo.AchievementVo;
import com.cnt.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/index")
public class IndexController {

    @Autowired
    private DonationsService donationsService;
    @Autowired
    private DonationRecordsService donationRecordsService;

    @GetMapping("/getTenDonation")
    public ResultVo<List<String>> getTenDonation(){
        return donationsService.getTenDonation();
    }

    @GetMapping("/achievement")
    public ResultVo<AchievementVo> achievement(){
        return donationsService.achievement();
    }

    @GetMapping("/chartDataDonation")
    public ResultVo<Map<Integer,Double>> chartDataDonation(@RequestParam(required = false) Integer year){
        if (year == 0){
            String y = new Date().toString().split(" ")[5];
            year = Integer.parseInt(y);
        }
        return donationRecordsService.chartDataDonation(year);
    }

}
